Skip to content

Add /perks - #53

Open
fghouri wants to merge 4 commits into
PatrickGTR:masterfrom
fghouri:cmd_perks
Open

fghouri wants to merge 4 commits into
PatrickGTR:masterfrom
fghouri:cmd_perks

Conversation

@fghouri

@fghouri fghouri commented Jan 6, 2021

Copy link
Copy Markdown

Add CMD /perks ( issue #4 )

  • I don't know how to use y_dialogs so I used the normal ones.
  • Will only work when player is in a vehicle
  • Used enums so you can easily edit Name, purpose and cost

Warning: Tested this on grandlarc, Should work on this gm but be sure to test!

@fghouri fghouri mentioned this pull request Jan 6, 2021
@CnRXoMoX

Copy link
Copy Markdown
Collaborator

Check my changes to know how Dialogs are used using inlines :) wait for @PatrickGTR to merge this

@CnRXoMoX
CnRXoMoX requested a review from PatrickGTR February 13, 2021 16:02

@PatrickGTR PatrickGTR left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check comments above.

MySQL_Bind(stmt_saveItem, 0, itemName, true);
MySQL_Bind(stmt_saveItem, 1, itemName, true);
MySQL_Bind(stmt_saveItem, 0, itemName);
MySQL_Bind(stmt_saveItem, 1, itemName);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed to allow raw string to be the input

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i compiled it, gives me an error but gonna fix it

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update package sampctl p ensure because I've recently updated the prepared statement library.

id
;

if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consitency

if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel");

if(sscanf(it, "u", id)) {
return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency, which style do you want to use?


if(sscanf(inputtext, "u", id))
return ShowPlayerDialog(playerid, DIALOG_PERKS_TP, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel");
for(new i = 0; i < sizeof(gPerkData); i++)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we wrap this in brackets please?

{
if(dialogid == DIALOG_PERKS)
{
inline perks(pid, dialogid, response, listitem, string:inputtext[]) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline function name is CameCase.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new /perks command intended to let players purchase perk actions (repair/flip/NOS/etc.) via a dialog UI, and updates an item-saving MySQL bind call to match the project’s existing MySQL_Bind usage pattern.

Changes:

  • Added /perks command implementation with a tablist dialog and perk metadata via an enum-backed table.
  • Wired the new command into the central commands include list.
  • Adjusted _SaveItem MySQL string binding calls in player_items.inc to use the 3-argument MySQL_Bind form used elsewhere in the codebase.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
gamemodes/core/player/player_items.inc Updates MySQL binding calls used when persisting item changes.
gamemodes/core/cmds/cmds.inc Registers the new perks command include.
gamemodes/core/cmds/cmds_perks.inc Implements /perks dialog + perk actions (repair/flip/NOS/teleport).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +45
switch (listitem)
{
case 0: // Repair vehicle
{
if(!IsPlayerInAnyVehicle(playerid)) // Somehow left vehicle?
return SendErrorMsg(playerid, "You must be in a vehicle to use this feature.");

RepairVehicle(vehicleid);

SendMsgF(playerid, -1, "[VEH-FIX] You have fixed your vehicle for {FFDC2E}$%d", gPerkData[listitem][E_COST]);
}

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The perk actions display a cost but never validate the player can afford it and never deduct money (e.g., RepairVehicle/Flip/Add NOS). This makes perks effectively free and contradicts the “each perks usage cost $” requirement; consider checking GetPlayerMoney(playerid) against gPerkData[listitem][E_COST] and calling GivePlayerMoney(playerid, -cost) once before executing the selected perk.

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +55
new
Float:VehZAngle
;

GetVehicleZAngle(vehicleid, VehZAngle);

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Flip vehicle” perk doesn’t actually change the vehicle orientation: it reads the current Z angle and sets the same value back, which is a no-op. Implement an actual flip (e.g., reposition slightly upward and reset rotation/angle) so overturned vehicles are reliably righted.

Suggested change
new
Float:VehZAngle
;
GetVehicleZAngle(vehicleid, VehZAngle);
new
Float:VehX,
Float:VehY,
Float:VehZ,
Float:VehZAngle
;
GetVehiclePos(vehicleid, VehX, VehY, VehZ);
GetVehicleZAngle(vehicleid, VehZAngle);
SetVehiclePos(vehicleid, VehX, VehY, VehZ + 1.0);

Copilot uses AI. Check for mistakes.
id
;

if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel");

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Cancel (resp == 0) this input dialog is immediately shown again, so the user cannot exit the teleport dialog. Cancel should return (or optionally return to the main perks dialog) instead of re-opening the same input prompt.

Suggested change
if(!resp) return Dialog_ShowCallback(playerid, using inline teleportInline, DIALOG_STYLE_INPUT, "{FFFFFF}Teleport To A Player", "Input a valid player name/id", "Select", "Cancel");
if(!resp) return 1;

Copilot uses AI. Check for mistakes.
Comment on lines +91 to +96
new Float:x, Float:y, Float:z;
new interior = GetPlayerInterior(playerid), vm = GetPlayerVirtualWorld(playerid);
GetPlayerPos(id, x, y, z);
SetPlayerPos(playerid, x, y, z);
SetPlayerInterior(playerid, interior);
SetPlayerVirtualWorld(playerid, vm);

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This teleport uses the player’s current interior/virtual world and re-applies them after moving, instead of switching to the target’s interior/virtual world. If the target is in a different interior/VW, the teleporter will likely end up desynced/invisible; capture interior/VW from the target player and apply those.

Copilot uses AI. Check for mistakes.
SetPlayerInterior(playerid, interior);
SetPlayerVirtualWorld(playerid, vm);

SendMsgF(playerid, -1, "[PERK-TP] You have successfully teleported to %s", id);

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success message formats an integer player id with "%s", which will be interpreted as a string pointer and can print garbage or crash. Use an integer/player formatter (e.g., %d or the project’s %p pattern) and/or resolve the target’s name before formatting.

Suggested change
SendMsgF(playerid, -1, "[PERK-TP] You have successfully teleported to %s", id);
SendMsgF(playerid, -1, "[PERK-TP] You have successfully teleported to %d", id);

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +26
new
perksStr[256]
;

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perksStr is only 256 bytes, but the tablist rows include multiple long strings and color codes; with the current 4 entries it’s likely to truncate, and adding more perks will worsen it. Increase the buffer (e.g., 512/1024) or build the string with bounds-aware concatenation.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +3
#define DIALOG_PERKS 69
#define DIALOG_PERKS_TP 6970

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dialog ID defines are currently unused because Dialog_ShowCallback isn’t passed an explicit dialog id here. Consider removing them to avoid confusion/collisions, or switch to APIs that use these IDs consistently.

Suggested change
#define DIALOG_PERKS 69
#define DIALOG_PERKS_TP 6970

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +27
CMD:perks(playerid, params[])
{
new
perksStr[256]
;

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says the command “will only work when player is in a vehicle,” but /perks can be opened on foot and the Teleportation option works without a vehicle check. Either enforce the in-vehicle requirement before showing the dialog or adjust the description/feature set to match intended behavior.

Copilot uses AI. Check for mistakes.
@fghouri

fghouri commented May 4, 2026

Copy link
Copy Markdown
Author

I'm just seeing these comments. This project still up? and this PR never made it in?

@s4marium

s4marium commented May 4, 2026

Copy link
Copy Markdown
Contributor

Yeah, the project is still up, but the PR needs some revisions before it can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants